package tlias.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tlias.service.EmpService;
import tlias.annotation.Crud;
import tlias.pojo.Emp;
import tlias.pojo.EmpsRequestParam;
import tlias.pojo.Result;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpsController {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result list(EmpsRequestParam param) {
        log.info("分页查询，参数：{}",param);
        Result result = Result.success(empService.getAllEmps(param));
        log.info("返回结果：{}", result);
        return result;

    }
    @DeleteMapping
    @Crud
    public Result delete(Integer[] ids) {
        log.info("删除员工：{}", ids);
        empService.delete(ids);
        return Result.success();
    }
    @PostMapping
    @Crud
    public Result add(@RequestBody Emp emp) {
        log.info("新增员工，员工信息：{}", emp);
        empService.add(emp);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("根据id查询员工信息：{}", id);
        return Result.success(empService.getById(id));
    }
    @PutMapping
    @Crud
    public Result update(@RequestBody Emp emp) {
        log.info("修改员工信息：{}", emp);
        empService.update(emp);
        return Result.success();
    }
}
